package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbCustomer;
import com.group.service.CustomerService;

@Controller
@RequestMapping("/customer")
public class CustomerController {
     @Autowired
     private CustomerService customerService;
     @RequestMapping("customerinfo.action")
     public String customerPage(){
    	 return "info/customer/customer";
     }
     
     //查询所有的客户信息
     @RequestMapping("/query.action")
     @ResponseBody
     public List<TbCustomer> query(TbCustomer customer){
    	 return customerService.query(customer);
     }
     
     
     //通过Id查询客户的姓名
     @RequestMapping("/getcustomerNameById.action")
     @ResponseBody
     public String customerName(String id){
    	 return customerService.query(id);
     }
     //通过Id查询客户的信息
     @RequestMapping("/getCustomerInfoById.action")
     @ResponseBody
     public TbCustomer getCustomerInfoBId(String customerId){
    	 return customerService.getCustomerInfoById(customerId);
     }
     
     //查询所有的客户信息
     @RequestMapping("/getAllcustomer.action")
     @ResponseBody
     public List<TbCustomer> getAllCustomer(Model model){
    	 return customerService.getAllCustomers();
     }
     //添加新客户
     @RequestMapping("/save.action")
     @ResponseBody
     public Map<String, String> saveCustomerInfo(HttpServletRequest request, TbCustomer customer) {
 		Map<String, String> map = customerService.saveCustomerInfo(request, customer); 
 		return map;
 	}
     //修改客户的信息
     @RequestMapping("contract/customer/update.action")
     @ResponseBody
     public Map<String, String> updateCustomerInfo(TbCustomer customer){
    	 return customerService.updateCustomerInfo(customer);
     }
     //通过客户姓名查询客户id
     @RequestMapping("/getcustomerIdbyName")
     @ResponseBody
     public String getcustomerIdbyName(String customerName){
    	 return customerService.getcustomerIdbyName(customerName);
     }
     //重置客户登陆密码
     @RequestMapping("/resetCustomerPassword.action")
     @ResponseBody
     public Map<String,String> resetCustomerPassword(String customerId){
    	 return customerService.resetCustomerPassword(customerId);
     }
     //删除客户信息
     @RequestMapping("/deleteCustomerInfo.action")
     @ResponseBody
     public Map<String,String> deleteCustomerInfo(@RequestParam(value = "roleIds[]")String[] customerIds){
    	 Map<String,String> map = customerService.deleteCustomerInfo(customerIds);
    	 return map;
     }
     //校验客户登录名是否重复
     @RequestMapping("/CheckCustomerLoginName.action")
     @ResponseBody
     public String CheckCustomerLoginName(String loginName){
    	 String str = customerService.checkLoginName(loginName);
    	 return str;
     }
     //校验客户名是否存在
     @RequestMapping("/CheckCustomerName.action")
     @ResponseBody
     public String CheckCustomerName(String customerName){
    	 String str = customerService.CheckCustomerName(customerName);
    	 return str;
     }
     
}























